/**
 * 
 */
package com.door.erp.controller;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.door.erp.dwz.DwzResponse;
import com.door.erp.model.Area;
import com.door.erp.model.Color;
import com.door.erp.model.Supplier;
import com.door.erp.pager.Pager;
import com.door.erp.sevice.AreaService;

/**
 * @author xiaolongwei@gmail.com
 *
 * 
 */
@Controller
@RequestMapping(value = "/area")
public class AreaController {
	@Resource(name="areaService", type=AreaService.class)
	private AreaService areaService;
	@RequestMapping(value = "/save.do")
	public ModelAndView save(Area area) {
		areaService.add(area);
		DwzResponse resonse = new DwzResponse();
		resonse.setNavTabId("area");
		ModelAndView mv = new ModelAndView("dwzresponse");	
		mv.addObject("response", resonse);
		return mv;
	}
	@RequestMapping(value = "/add")
	public ModelAndView add() {
		ModelAndView mv = new ModelAndView("area/add");
		return mv;
	}
	@RequestMapping(value = "/update")
	public ModelAndView update(Area area) {		
		areaService.modify(area);
		DwzResponse resonse = new DwzResponse();
		resonse.setNavTabId("area");
		ModelAndView mv = new ModelAndView("dwzresponse");	
		mv.addObject("response", resonse);
		return mv;
	}
	@RequestMapping(value = "/edit/{id}.do")
	public  ModelAndView  edit(@PathVariable(value="id") Long id ) {
		ModelAndView mv = new ModelAndView("area/edit");
		Area area = areaService.getObject(id);
		mv.addObject("area",area);
		return mv;
	}
	@RequestMapping(value = "/delete/{id}.do")
	public ModelAndView delete(@PathVariable(value="id") Long id ) {
		ModelAndView mv = new ModelAndView("dwzresponse");
		areaService.delete(id);
	//	mv.addObject("stock", StockManager.pop());
		DwzResponse resonse = new DwzResponse();	
		resonse.setNavTabId("area");
		mv.addObject("response", resonse);
		return mv;
	}
	@RequestMapping(value = "/find/{id}")
	public ModelAndView find(@PathVariable(value="id") Long id) {
		ModelAndView mv = new ModelAndView("index/index");
	//	mv.addObject("stock", StockManager.pop());
		return mv;
	}
	@RequestMapping(value = "/index.do")
	public ModelAndView index(Pager pager) {
		ModelAndView mv = new ModelAndView("area/areaIndex");	
		List<Area> areas = areaService.getAll(new HashMap(), pager);
		mv.addObject("areas", areas);
		mv.addObject("pager", pager);
		return mv;
	}
	@RequestMapping(value = "/lookuplist.do")
	public ModelAndView employeeLookUp(Pager pager) {
		ModelAndView mv = new ModelAndView("area/area_lookup");	
		List<Area> areas= areaService.getAll(new HashMap(), pager);
		mv.addObject("areas", areas);
		return mv;
	}
}
